<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv=content-type content="text/html; charset=UTF-8">
<base href="<%=basePath%>">
<title>YP.ShO购</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0"> 
<link rel="stylesheet" href="css/bootstrap.css"></link>
<link rel="stylesheet" href="css/style.css"></link>
<link rel="stylesheet" href="css/myButton.css"></link>
<link rel="stylesheet" href="css/sellerStyle.css"></link>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.easydropdown.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<style type="text/css">
.form p {
	margin-bottom: 15px;
}

.form label {
	width: 8em;
}
table{
			width:100%;
			border-color:#009999;
			border-collapse: collapse;
			margin:5px 0 5px 0;
		}
		table tr td{
			border:1px solid;
			border-color: #009999;
			text-align:center;
		}
		table thead td{
			background-color: #009999;
			height:50px;
		}
		table tbody td{
			height:100px;
			border-collapse: collapse;
			border-width: 0px 1px 1px 1px;
			border-color: #009999;
		}
		table tbody tr td input[type="button"]{
			background: #8BB682;
		}
		table tbody tr td input[type="button"]:hover{
			background: #893139;
		}
</style>
</head>
<body>
	<%@include file="../common/head.jsp"%>
	<div class="menu"></div>
	<div class="men">
		<div class="container">
			<div class="col-md-3 sidebar">
				<div class="block block-layered-nav">
					<div class="block-title">
						<strong><span>我的YPShO购</span></strong>
					</div>
					<div class="block-content">
						<dl id="narrow-by-list">
							<dt class="last odd">用户中心</dt>
							<dd class="last odd">
								<ol>
									<li><a href="userInforView">个人信息管理</a></li>
								</ol>
							</dd>
							<dt class="last odd">我是买家</dt>
							<dd class="last odd">
								<ol>
									<li><a href="userOrders">我的订单管理</a></li>
									<li><a href="userCart">我的购物车</a></li>
								</ol>
							</dd>
							<dt class="last odd">我是卖家</dt>
							<dd class="last odd">
								<ol>
									<li><a href="sellerOrders" style="color:#e05b5b">我的订单管理</a></li>
									<li><a href="sellerGoods">我的商品管理</a></li>
								</ol>
							</dd>
						</dl>
					</div>
				</div>
			</div>
			<div class="col-md-9">
				<div class="mens-toolbar">
					<div class="sort">
						<div class="sort-by">
							<label>我的订单</label>
						</div>
					</div>
				</div>
				<div class="form">
					<div id="userOrders">
					</div>
					
						<%--<tr height="80px" style="border: rgb(197, 197, 197) solid 0.25px;">
							<td>订单编号</td>
							<td>收件人</td>
							<td>收件地址</td>
							<td>电话号码</td>
							<td>金额</td>
							<td>创建时间</td>
						</tr>
						--%>
						<%--<s:iterator value="Olist" id="orders">
							<table>
								<tr>
									<td colspan="8">下单时间: ${orders.creDate } &nbsp;&nbsp;订单编号: ${orders.num }</td>
								</tr>
								<tr>
									<td>${orders.receiver }</td>
									<td>${orders.address }</td>
									<td>${orders.phone }</td>
									<td>${orders.money }</td>
									<td>${orders.creDate }</td>
								</tr>
							</table>
						</s:iterator>
					--%>
				</div>
			</div>
		</div>
	</div>

	<%@include file="../common/footer.jsp"%>
	<script type="text/javascript">
		$(document).ready(function(){
			getSellerOrders();
		});
		//改变订单状态的页面跳转
		function changeOrderStatus(orderNum,settings){
			var temp = document.createElement("form");
			temp.action = "changeOrderStatusAsSeller.action";
			temp.method = "POST";
			temp.style.display = "none";
			
			var num = document.createElement("input");
			num.name = "orderNum";
			num.type = "hidden";
			num.value = orderNum;
			temp.appendChild(num);
			
			var sets = document.createElement("input");
			sets.name = "settings";
			sets.type = "hidden";
			sets.value = settings;
			temp.appendChild(sets);
			$(document.body).append(temp);
			temp.submit();
			return temp;
			
			//window.location.href = "<%=basePath%>changeOrderStatusAsSeller.action?orderNum="+orderNum+"&settings="+settings;
		}
		function getSellerOrders(){
			$.ajax({
				url:"getSellerOrdersAsJson.action",
				type:"post",
				data:{},
				dataType:"json",
				success:function(data){
					var datas = eval(data);
					//console.log(data);
					if(datas.result.length > 0){
						
						var ordersStr = "";
						
						for(var i=0;i<datas.result.length;i++){
							var o = datas.result[i];
							var orderStr = "<table>";
							orderStr += "<thead><tr>";
							orderStr += "<td width=\"15%\">下单时间: " + o.createDate + "</td>";
							orderStr += "<td width=\"35%\">订单号:" + o.orderNo + "</td>";
							orderStr += "<td colspan=\"5\" width=\"50%\">买家: " + o.buyer + "</td>";
							orderStr += "</tr>";
							orderStr += "</thead><tbody>";
							if(o.goods.length > 0){//遍历商品开始
								var isStatusWritten = false;
								for(var j=0;j<o.goods.length;j++){
									var g = o.goods[j];
									orderStr += "<tr><td style=\"border-right:0px\" width=\"5%\"><img src=\""+g.img+"\" style=\"width:60px;height:60px\"/></td>";	//商品图片
									orderStr += "<td style=\"border-left:0px\" width=\"35%\">" + g.name + "</td>"	//商品名称
									orderStr += "<td width=\"5%\">" + g.price + "￥</td>"		//价格
									orderStr += "<td width=\"5%\">" + g.amount + "</td>"	//数量
									//此处开始写订单总价, 状态和可操作行为
									if(!isStatusWritten){
										var rowspanStr = "";
										if(o.goods.length > 1){//如果该订单只有一件商品
											rowspanStr = "rowspan=\"" + o.goods.length + "\"";
										}
										
										orderStr += "<td "+rowspanStr+" width=\"5%\">" + o.totalPrice + "￥</td>";//订单总价
										orderStr += "<td "+rowspanStr+" width=\"25%\">" + o.status + "</td>";	//订单当前状态
										//订单可操作行为
										var avaliableActions = o.avaliableStatus.split("-");
										if(avaliableActions[1] == "false"){//如果当前为不显示任何
											orderStr += "<td "+rowspanStr+" width=\"20%\"></td>";
										}else{
											orderStr += "<td "+rowspanStr+" width=\"20%\"><input type=\"button\" value=\"" + avaliableActions[0] + "\" onclick=\"changeOrderStatus('" + o.orderNo + "','"+o.avaliableStatus+"')\" /></td>";
										}
										isStatusWritten = true;
									}
									orderStr += "</tr>";
								}
							}
							orderStr += "</tbody></table>";
							ordersStr += orderStr;
						}
						$("#userOrders").html(ordersStr);
					}	
				}
			})
		}
	</script>
</body>
</html>
